<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>select组件</title>
    <link rel="stylesheet" href="./css/style.css">
</head>

<body>
    <div id="app">
        <div style="float: left;">
            <h2>自定义下拉框</h2>
            <custom-select btn-value="查询" :list="list1"></custom-select>
        </div>

        <!-- is特殊属性 -->
        <div style="float: left;">
            <br/>
            <h2>自定义下拉框</h2>
            <custom-select btn-value="搜索" :list="list2"></custom-select>
        </div>

    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        //注册组件
        Vue.component("custom-select", {
            data: function () {
                return {
                    selectShow: false,
                    val: ''
                }
            },
            props: ["btnValue", "list"],
            template: ` <section class="wrap">
            <div class="searchIpt clearFix">
                <div class="clearFix searchtop">
                    <input type="text" class="keyword" @click="selectShow=!selectShow" :value="val">
                    <input type="button"  :value="btnValue" class="btn">
                    <span></span>
                </div>
                <custom-list @receive="changevalue" v-show="selectShow" :list="list"></custom-list>
            </div>
        </section>
       `,
            methods: {
                changevalue: function (valve) {
                    this.val = valve;
                }
            }
        });
        Vue.component("custom-list", {
            props: ["list"],
            template: `
            <ul class="list">
                    <li v-for="item of list" @click="selectValueHandle(item)">{{item}}</li>
            </ul>
            `,
            methods: {
                selectValueHandle: function (item) {
                    this.$emit("receive", item);
                }
            }
        });
        new Vue({
            el: "#app",
            data: {
                list1: ["北京", "上海", "杭州"],
                list2: ["2011", "2012", '2013']
            }
        });
    </script>
</body>

</html>